package course.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
<<<<<<< HEAD
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import course.controller.CourseControllerListener;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;

public class LoginFrame extends JFrame {
	private static final long serialVersionUID = -6248167722194350825L;
	private DbConnection db=new DbConnection();
	private UserDaoImpl userDao=new UserDaoImpl();
	private JTextField nameTextField;
	private JTextField passWordTextField;
	private JButton loginButton;
	private JButton cancelButton;
	public static JRadioButton stuRadioButton;
	public static JRadioButton  teaRadioButton;
	public static JRadioButton  deaRadioButton;
	private CourseControllerListener controllerListener;
	public static String name;
	public static String passWord;
    public static String type;
	public LoginFrame() {
		this.controllerListener = new CourseControllerListener();
		this.controllerListener.setLoginFrame(this); 
		//init();
		this.setTitle("登录");
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		//this.setLocation(600, 300);
		this.setBounds(100, 100, 770, 500);
		//this.setSize(800, 560);
		this.setResizable(true);
		this.setVisible(true);

	
//		JLabel bg = new JLabel(new ImageIcon("backgroup.jpg"));
//		this.setContentPane(bg);

		JPanel contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(73, 37, 611, 362);
		contentPane.add(panel);
		panel.setLayout(null);

		JLabel label = new JLabel("教务管理系统");
		label.setBounds(236, 15, 159, 40);
		label.setFont(new Font("微软雅黑", Font.BOLD, 25));
		panel.add(label);

		JLabel account = new JLabel("账号");
		ImageIcon accountIcon = new ImageIcon(LoginFrame.class.getResource("/account.png"));
		account.setIcon(accountIcon);
		account.setBounds(118, 92, 88, 40);
		account.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		panel.add(account);

	
		JLabel password = new JLabel("密码");
		ImageIcon passwordIcon = new ImageIcon(LoginFrame.class.getResource("/password.png"));
		password.setIcon(passwordIcon);
		password.setBounds(118, 158, 88, 40);
		password.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		panel.add(password);

//		JLabel user = new JLabel("用户");
//		user.setBounds(320, 286, 30, 25);
//		user.setFont(new Font("微软雅黑", Font.PLAIN, 14));
//		this.add(user);

		loginButton = new JButton("登录");
		// 回车登录
		getRootPane().setDefaultButton(loginButton);
		ImageIcon loginIcon = new ImageIcon(LoginFrame.class.getResource("/login.png"));
		loginButton.setIcon(loginIcon);
		 loginButton.addActionListener(controllerListener);
		 loginButton.setActionCommand("addLoginDialog");
		loginButton.setBounds(143, 302, 96, 29);
		panel.add(loginButton);

		cancelButton = new JButton("重置");
		ImageIcon cancelIcon = new ImageIcon(LoginFrame.class.getResource("/cancel.png"));
		cancelButton.setIcon( cancelIcon);
		cancelButton.addActionListener(controllerListener);
		cancelButton.setActionCommand("addCancelDialog");
		cancelButton.setBounds(340, 302, 96, 29);
		panel.add(cancelButton);
		nameTextField = new JTextField();
		//nameTextField.setToolTipText("请输入学号或教职工号:");
		nameTextField.setBounds(220, 99, 255, 29);
		panel.add(nameTextField);
		 passWordTextField = new JTextField();
		 //passWordTextField.setToolTipText("请输入密码:");
		passWordTextField.setBounds(220, 165, 255, 29);
		panel.add(passWordTextField);
		stuRadioButton = new JRadioButton("学生");
		ImageIcon stuRadioIcon = new ImageIcon(LoginFrame.class.getResource("/stu.png"));
		stuRadioButton.setIcon(stuRadioIcon);
//		stuRadioButton.addActionListener(controllerListener);
//		stuRadioButton.setActionCommand("stuDialog");
		stuRadioButton.setBounds(354, 234, 88, 29);
		panel.add(stuRadioButton);
		
		 teaRadioButton = new JRadioButton("教师");
		 ImageIcon teaRadioIcon = new ImageIcon(LoginFrame.class.getResource("/tea.png"));
		 teaRadioButton.setIcon(teaRadioIcon);
//		teaRadioButton.addActionListener(controllerListener);
//		teaRadioButton.setActionCommand("teaDialog");
		teaRadioButton.setBounds(259, 234, 88, 29);
		panel.add(teaRadioButton);
		
		 deaRadioButton = new JRadioButton("教务员");
		 ImageIcon  deaRadioIcon = new ImageIcon(LoginFrame.class.getResource("/dea.png"));
		 deaRadioButton.setIcon( deaRadioIcon);
//		deaRadioButton.addActionListener(controllerListener);
//		deaRadioButton.setActionCommand("deaDialog");
		deaRadioButton.setBounds(143, 234, 88, 29);
		panel.add(deaRadioButton);
	   ButtonGroup group = new ButtonGroup();
		group.add(stuRadioButton);
		group.add(teaRadioButton);
		group.add(deaRadioButton);
		 
		 
		//设置默认提示信息，字体颜色设置淡灰色
		nameTextField.setText("请输入学号或教职工号:");     
		nameTextField.setToolTipText("请输入学号或教职工号:");
		nameTextField.setForeground(new Color(204,204,204));
		 passWordTextField.setText("请输入密码:");    
		 passWordTextField.setToolTipText("请输入密码:");
		 passWordTextField.setForeground(new Color(204,204,204));
		//设置焦点监听
		nameTextField.addFocusListener(new FocusListener() {
		    @Override
		    public void focusGained(FocusEvent e) {
		 
		       //当点击输入框时，里面的内容为提示信息时，清空内容，将其字体颜色设置为正常黑色。
		       if(nameTextField.getText().equals("请输入学号或教职工号:")){
		    	   nameTextField.setText("");
		    	   nameTextField.setForeground(Color.BLACK);
		       }
		    }
		 
		    @Override
		    public void focusLost(FocusEvent e) {
		 
		       //当失去焦点时，判断是否为空，若为空时，直接显示提示信息，设置颜色
		       if(nameTextField.getText().length()<1){
		    	   nameTextField.setText("请输入学号或教职工号:");
		    	   nameTextField.setForeground(new Color(204,204,204));
		       }
		    }
		});
		passWordTextField.addFocusListener(new FocusListener() {
		    @Override
		    public void focusGained(FocusEvent e) {
		       if(passWordTextField.getText().equals("请输入密码:")){
		    	   passWordTextField.setText("");
		    	   passWordTextField.setForeground(Color.BLACK);
		       }
		    }
		 
		    @Override
		    public void focusLost(FocusEvent e) {
		       if(passWordTextField.getText().length()<1){
		    	   passWordTextField.setText("请输入密码:");
		    	   passWordTextField.setForeground(new Color(204,204,204));
		       }
		    }
	});
		
		
//		
//		JPanel panel = new JPanel(null);
//		panel.setBounds(83, 82, 611, 362);
//		// panel.setBackground(Color.yellow);
//		panel.setBorder(BorderFactory.createLineBorder(Color.gray));
//		panel.setLayout(null);
//		this.add(panel);
//		JLabel logo = new JLabel("综合教务管理服务平台",JLabel.CENTER);
//		//logo.setBounds(20, 20, 180, 25);
//		logo.setBounds(118, 92, 88, 40);
//		logo.setFont(new Font("微软雅黑", Font.BOLD, 20));
//		logo.setForeground(Color.orange);
//		this.add(logo);
    //权限尝试，无用
//		t1.addMouseListener(new MouseAdapter() {
//			public void mouseClicked(MouseEvent e) {
//				String type = list[t1.getSelectedIndex()];
//				if (type.equals("学生")) {
//					name = "李钦萍";
//					passWord = "123456";
//				}
//				if (type.equals("教师")) {
//					name = "邓成剑";
//					passWord = "654321";
//				}
//				System.out.println(name);
//				if (type.equals("教务员")) {
//					name = "林旭";
//					passWord = "234567";
//				}
//			}
//		});
//		t1.addActionListener(new ActionListener() {
//
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				if(e.getSource() instanceof JComboBox){
//					if(e.getSource().equals("学生")) {
//						name = "李钦萍";
//					passWord = "123456";
//					}
//				}
//				
//			}
//			
//		});
//		System.out.println(t1.getSelectedItem().toString().trim());
//        System.out.println(t1.getSelectedIndex());
        
		
	}
       public  String getUserName() {
    	   String userNo = null;
    	   File f1 = new File("user.txt");
    	   InputStream in = null;
    	   try {
    	       in = new FileInputStream(f1);
    	       byte[] u = new byte[10];
    	       int len = -1;
    	       while((len = in.read(u))!=-1) {
    		     userNo = new String(u,0,len);
    	   }
       } catch(IOException ex) {
    	   ex.printStackTrace();
       }
       return userNo;
}
=======
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import course.controller.CourseControllerListener;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;

public class LoginFrame extends JFrame {
	private static final long serialVersionUID = -6248167722194350825L;
	private DbConnection db=new DbConnection();
	private UserDaoImpl userDao=new UserDaoImpl();
	private JTextField nameTextField;
	private JTextField passWordTextField;
	private JButton loginButton;
	private JButton cancelButton;
	public static JRadioButton stuRadioButton;
	public static JRadioButton  teaRadioButton;
	public static JRadioButton  deaRadioButton;
	private CourseControllerListener controllerListener;
	public static String name;
	public static String passWord;
    public static String type;
	public LoginFrame() {
		this.controllerListener = new CourseControllerListener();
		this.controllerListener.setLoginFrame(this); 
		//init();
		this.setTitle("登录");
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		//this.setLocation(600, 300);
		this.setBounds(100, 100, 770, 500);
		//this.setSize(800, 560);
		this.setResizable(true);
		this.setVisible(true);

	
//		JLabel bg = new JLabel(new ImageIcon("backgroup.jpg"));
//		this.setContentPane(bg);

		JPanel contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(73, 37, 611, 362);
		contentPane.add(panel);
		panel.setLayout(null);

		JLabel label = new JLabel("教务管理系统");
		label.setBounds(236, 15, 159, 40);
		label.setFont(new Font("微软雅黑", Font.BOLD, 25));
		panel.add(label);

		JLabel account = new JLabel("账号");
		ImageIcon accountIcon = new ImageIcon(LoginFrame.class.getResource("/account.jpg"));
		account.setIcon(accountIcon);
		account.setBounds(118, 92, 88, 40);
		account.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		panel.add(account);

	
		JLabel password = new JLabel("密码");
		ImageIcon passwordIcon = new ImageIcon(LoginFrame.class.getResource("/password.png"));
		password.setIcon(passwordIcon);
		password.setBounds(118, 158, 88, 40);
		password.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		panel.add(password);

//		JLabel user = new JLabel("用户");
//		user.setBounds(320, 286, 30, 25);
//		user.setFont(new Font("微软雅黑", Font.PLAIN, 14));
//		this.add(user);

		loginButton = new JButton("登录");
		System.out.println(LoginFrame.class.getResource("/login.png"));
		ImageIcon loginIcon = new ImageIcon(LoginFrame.class.getResource("/login.png"));
		loginButton.setIcon(loginIcon);
		 loginButton.addActionListener(controllerListener);
		 loginButton.setActionCommand("addLoginDialog");
		loginButton.setBounds(143, 302, 96, 29);
		panel.add(loginButton);

		cancelButton = new JButton("重置");
		ImageIcon cancelIcon = new ImageIcon(LoginFrame.class.getResource("/cancel.png"));
		cancelButton.setIcon( cancelIcon);
		cancelButton.addActionListener(controllerListener);
		cancelButton.setActionCommand("addCancelDialog");
		cancelButton.setBounds(340, 302, 96, 29);
		panel.add(cancelButton);
		nameTextField = new JTextField();
		//nameTextField.setToolTipText("请输入学号或教职工号:");
		nameTextField.setBounds(220, 99, 255, 29);
		panel.add(nameTextField);
		 passWordTextField = new JTextField();
		 //passWordTextField.setToolTipText("请输入密码:");
		passWordTextField.setBounds(220, 165, 255, 29);
		panel.add(passWordTextField);
		stuRadioButton = new JRadioButton("学生");
		ImageIcon stuRadioIcon = new ImageIcon(LoginFrame.class.getResource("/stu.png"));
		stuRadioButton.setIcon(stuRadioIcon);
//		stuRadioButton.addActionListener(controllerListener);
//		stuRadioButton.setActionCommand("stuDialog");
		stuRadioButton.setBounds(354, 234, 88, 29);
		panel.add(stuRadioButton);
		
		 teaRadioButton = new JRadioButton("教师");
		 ImageIcon teaRadioIcon = new ImageIcon(LoginFrame.class.getResource("/tea.png"));
		 teaRadioButton.setIcon(teaRadioIcon);
//		teaRadioButton.addActionListener(controllerListener);
//		teaRadioButton.setActionCommand("teaDialog");
		teaRadioButton.setBounds(259, 234, 88, 29);
		panel.add(teaRadioButton);
		
		 deaRadioButton = new JRadioButton("教务员");
		 ImageIcon  deaRadioIcon = new ImageIcon(LoginFrame.class.getResource("/dea.png"));
		 deaRadioButton.setIcon( deaRadioIcon);
//		deaRadioButton.addActionListener(controllerListener);
//		deaRadioButton.setActionCommand("deaDialog");
		deaRadioButton.setBounds(143, 234, 88, 29);
		panel.add(deaRadioButton);
	ButtonGroup group = new ButtonGroup();
		group.add(stuRadioButton);
		group.add(teaRadioButton);
		group.add(deaRadioButton);
		 
		 
		//设置默认提示信息，字体颜色设置淡灰色
		nameTextField.setText("请输入学号或教职工号:");     
		nameTextField.setToolTipText("请输入学号或教职工号:");
		nameTextField.setForeground(new Color(204,204,204));
		 passWordTextField.setText("请输入密码:");    
		 passWordTextField.setToolTipText("请输入密码:");
		 passWordTextField.setForeground(new Color(204,204,204));
		//设置焦点监听
		nameTextField.addFocusListener(new FocusListener() {
		    @Override
		    public void focusGained(FocusEvent e) {
		 
		       //当点击输入框时，里面的内容为提示信息时，清空内容，将其字体颜色设置为正常黑色。
		       if(nameTextField.getText().equals("请输入学号或教职工号:")){
		    	   nameTextField.setText("");
		    	   nameTextField.setForeground(Color.BLACK);
		       }
		    }
		 
		    @Override
		    public void focusLost(FocusEvent e) {
		 
		       //当失去焦点时，判断是否为空，若为空时，直接显示提示信息，设置颜色
		       if(nameTextField.getText().length()<1){
		    	   nameTextField.setText("请输入学号或教职工号:");
		    	   nameTextField.setForeground(new Color(204,204,204));
		       }
		    }
		});
		passWordTextField.addFocusListener(new FocusListener() {
		    @Override
		    public void focusGained(FocusEvent e) {
		       if(passWordTextField.getText().equals("请输入密码:")){
		    	   passWordTextField.setText("");
		    	   passWordTextField.setForeground(Color.BLACK);
		       }
		    }
		 
		    @Override
		    public void focusLost(FocusEvent e) {
		       if(passWordTextField.getText().length()<1){
		    	   passWordTextField.setText("请输入密码:");
		    	   passWordTextField.setForeground(new Color(204,204,204));
		       }
		    }
	});
		
		
//		
//		JPanel panel = new JPanel(null);
//		panel.setBounds(83, 82, 611, 362);
//		// panel.setBackground(Color.yellow);
//		panel.setBorder(BorderFactory.createLineBorder(Color.gray));
//		panel.setLayout(null);
//		this.add(panel);
//		JLabel logo = new JLabel("综合教务管理服务平台",JLabel.CENTER);
//		//logo.setBounds(20, 20, 180, 25);
//		logo.setBounds(118, 92, 88, 40);
//		logo.setFont(new Font("微软雅黑", Font.BOLD, 20));
//		logo.setForeground(Color.orange);
//		this.add(logo);
    //权限尝试，无用
//		t1.addMouseListener(new MouseAdapter() {
//			public void mouseClicked(MouseEvent e) {
//				String type = list[t1.getSelectedIndex()];
//				if (type.equals("学生")) {
//					name = "李钦萍";
//					passWord = "123456";
//				}
//				if (type.equals("教师")) {
//					name = "邓成剑";
//					passWord = "654321";
//				}
//				System.out.println(name);
//				if (type.equals("教务员")) {
//					name = "林旭";
//					passWord = "234567";
//				}
//			}
//		});
//		t1.addActionListener(new ActionListener() {
//
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				if(e.getSource() instanceof JComboBox){
//					if(e.getSource().equals("学生")) {
//						name = "李钦萍";
//					passWord = "123456";
//					}
//				}
//				
//			}
//			
//		});
//		System.out.println(t1.getSelectedItem().toString().trim());
//        System.out.println(t1.getSelectedIndex());
        
		
	}
       
>>>>>>> refs/remotes/origin/master
		public JTextField getNameTextField() {
			return nameTextField;
		}
		public void setNameTextField(JTextField nameTextField) {
			this.nameTextField = nameTextField;
		}
		public JTextField getPassWordTextField() {
			return passWordTextField;
		}
		public void setPassWordTextField(JTextField passWordTextField) {
			this.passWordTextField = passWordTextField;
		}
 }

